
package com.android.finaltracer.model;

import org.json.JSONException;
import org.json.JSONObject;

public class CommandInfo extends DataFormatBasic {
    public final static int COMMAND_NOTIFY_SIM_CHANGED = 1;
    public final static int COMMAND_HANDSHAKE_REQ = COMMAND_NOTIFY_SIM_CHANGED + 1;
    public final static int COMMAND_HANDSHAKE_CNF = COMMAND_HANDSHAKE_REQ + 1;
    public final static int COMMAND_START_MONITOR_GPS_POSITION = COMMAND_HANDSHAKE_CNF + 1;
    public final static int COMMAND_STOP_MONITOR_GPS_POSITION = COMMAND_START_MONITOR_GPS_POSITION + 1;
    public final static int COMMAND_VERIFY_SUCCESS = COMMAND_STOP_MONITOR_GPS_POSITION + 1;
    private static final String TAG_COMMAND = "command";
    int mCommand;

    public CommandInfo() {
        super();
    }

    public CommandInfo(int mCommand) {
        this.mCommand = mCommand;
    }

    public void SetCommand(int mCommand) {
        this.mCommand = mCommand;
    }

    public int getCommand() {
        return mCommand;
    }

    public String encode() {
        String codeStr = "";
        try {
            JSONObject codeJson = new JSONObject(makeHeader());
            codeJson.put(TAG_BODY, new JSONObject().put(TAG_COMMAND, mCommand));
            codeStr += codeJson.toString();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return codeStr;
    }

    public boolean decode(String str) {
        try {
            JSONObject json = new JSONObject(str);
            mCommand = json.getInt(TAG_COMMAND);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return true;
    }

    @Override
    public int getType() {
        // TODO Auto-generated method stub
        return DataFormatBasic.TYPE_COMMAND_INFO;
    }
}
